import java.net.*;
import java.io.*;

public class LocalTalk {

    public static void main(String args[] ) {
     try {
	Socket sk = new Socket("pegasus.cs.csubak.edu", 8900);
	InputStream in = sk.getInputStream();
	OutputStream out = sk.getOutputStream();

        byte inMsg[] = new byte[100], outMsg[] = new byte[100];
 	String msg = "Client: " + args[0] + ", Message: " ;
	int    num = 1, len;
	String str = null ;
	while ( true ) {
		str = msg + num++; 
		outMsg = str.getBytes();
		out.write( outMsg, 0, str.length());
		if ( in.available() > 0 ) {
			len = in.read(inMsg);
			System.out.println( new String(inMsg, 0, len) + " Last message sent: " + str + "\n");
		}

		Thread.sleep((int) ( Math.random() * 5000) +1000 );
	}
     } catch ( Exception e ) { e.printStackTrace(); }
   }
}
